<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">订单管理</h3>
            </div>
        </div>
        <div class="row">
            <form class="form-horizontal" data-parsley-validate>
                <div class="col-lg-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">订单详情</div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12 col-md-12">
                                	 <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">订单ID：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="orderId"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">订单编号：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="number"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">订单状态：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="status"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">订单归属：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="mallName"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">用户Id：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="accountId"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">微信昵称：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="accountNickname"></p>
                                        </div>
                                    </div>
                                    <div class="clearfix"></div>
                                    <hr>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">订单总价：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="totalPrice"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">实付金额：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="realPrice" style="color:red;"></p>
                                        </div>
                                    </div>
                                    <div class="clearfix"></div>
                                    <hr>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">购买订单时销售经理用户id：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="fatherAccountId"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">购买订单时销售经理用户昵称：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="fatherAccountNickname"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">购买订单时体验店用户id：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="shopAccountId"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">购买订单时体验店用户昵称：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="shopAccountNickname"></p>
                                        </div>
                                    </div>
                                    
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">当前销售经理用户id：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="currentfatherAccountId"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">当前销售经理用户昵称：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="currentfatherAccountNickname"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">当前体验店用户id：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="currentshopAccountId"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">当前体验店用户昵称：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="currentshopAccountNickname"></p>
                                        </div>
                                    </div>
                                    <div class="clearfix"></div>
                                    <hr>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">下单时间：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="createTime"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">付款时间：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="payTime"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">发货时间：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="sendTime"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">收货时间：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="receiveTime"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">收货人姓名：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="addressFullName"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">收货人手机号：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="addressMobileNumber"></p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">详细地址：</label>
                                        <div class="col-lg-8 col-md-12">
                                            <p id="addressDetail"></p>
                                        </div>
                                    </div>
                                    <div class="clearfix"></div>
                                    <hr>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">快递渠道：</label>
                                        <div class="col-lg-6 col-md-12">
                                            <p id="logisticsChannel">快递渠道</p>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-12">
                                        <label class="col-lg-4 clo-md-12 control-label">快递单号：</label>
                                        <div class="col-lg-6 col-md-12">
                                            <p id="logisticsNumber"></p>
                                        </div>
                                    </div>
                                    <div class="clearfix"></div>
                                    <hr>
                                    <div class="dataTable_wrapper">
                                        <table class="table table-striped table-bordered table-hover"
                                               id="dataTables-example">
                                            <thead>
                                            <tr>
                                                <th class="text-center" style="width:5%;">商品ID</th>
                                                <th class="text-center" style="width:11%;">商品名称</th>
                                                <th class="text-center" style="width:11%;">商品图片</th>
                                                <th class="text-center" style="width:25%;">商品规格</th>
                                                <th class="text-center" style="width:5%;">商品单价</th>
                                                <th class="text-center" style="width:5%;">购买数量</th>
                                                <th class="text-center" style="width:5%;">退款状态</th>
                                                <th class="text-center" style="width:7.3%;">总价</th>
                                                <th class="text-center" style="width:7.3%;">操作</th>
                                            </tr>
                                            </thead>
                                            <tbody id="product">
	                                            <tr>
	                                                <td class="text-center" id="productId"></td>
	                                                <td class="text-center">
	                                                    <a href="javascript:void(0);" target="_blank"  id="productTitle"></a>
	                                                </td>
	                                                <td class="text-center"  id="productImage"></td>
	                                                <td class="text-center"  id="productPrice"></td>
	                                                <td class="text-center"  id="productCount"></td>
	                                                <td class="text-center"  id="productTotalPrice"></td>
	                                                <td class="text-center"  id="certificateNumber"></td>
	                                            </tr>
                                            </tbody>
                                        </table>
                                        
                                        <div class="modal fade" id="sendModel">
				                            <div class="modal-dialog">
				                                <div class="modal-content message_align">
				                                    <div class="modal-header">
				                                        <button class="close" type="button" data-dismiss="modal" aria-label="Close">
				                                            <span aria-hidden="true">×</span>
				                                        </button>
				                                        <h4 class="modal-title">证书信息</h4>
				                                    </div>
				                                    <div class="modal-body">				                                                     
				                                        <div class="clearfix"></div>
				                                        <div class="form-group" style="margin-bottom:30px;">
				                                            <label class="col-lg-3 clo-md-3 text-right"
				                                                   style="line-height:34px;">证书编号：</label>
				                                            <div class="col-lg-6 col-md-6">
				                                                <input class="form-control" id="certificate_number" type="text"  placeholder="证书编号">
				                                            </div>
				                                        </div>
				                                    </div>
				                                    <div class="modal-footer">
				                                        <input id="orderId_hidden" type="hidden">
				                                        <input id="productId_hidden" type="hidden">
				                                        <button class="btn btn-default" type="button" data-dismiss="modal">取消</button>
				                                        <a class="btn btn-danger" onclick="deliver_certificate_number()" data-dismiss="modal">保存</a>
				                                    </div>
				                                </div>
				                            </div>
				                        </div>
                                        
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>	
   	$(function(){
   		var orderId = "${orderId}";
  		var baseURL = "${webPath}/order/detail";
      	var json_package = {
           "head": {},
           "body": {
           	"orderId": orderId
           }
       	}
   		$.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
          if (typeof result == 'string') result = JSON.parse(result);
          if (result.body.result == '1') {
              alert(result.body.description)
          } else {
          	var order = result.body.order;
          	console.log(order);
          	
          	$("#status").text(order.status);
          	$("#number").text(order.number);
          	$("#orderId").text(order.id);
          	$("#mallName").text(order.mallName);
          	
          	$("#accountId").text(order.accountId);
          	$("#accountNickname").text(order.accountNickname);
          	
          	$("#createTime").text(order.createTime);
          	$("#payTime").text(order.payTime);
          	$("#sendTime").text(order.sendTime);
          	$("#receiveTime").text(order.receiveTime);
          	
          	$("#totalPrice").text(order.totalPrice);
          	$("#realPrice").text(order.realPrice);
          	
          	$("#fatherAccountId").text(order.fatherAccountId);
          	$("#fatherAccountNickname").text(order.fatherAccountNickname);
          	$("#shopAccountId").text(order.shopAccountId);
          	$("#shopAccountNickname").text(order.shopAccountNickname);
          	
          	$("#currentfatherAccountId").text(order.currentfatherAccountId);
          	$("#currentfatherAccountNickname").text(order.currentfatherAccountNickname);
          	$("#currentshopAccountId").text(order.currentshopAccountId);
          	$("#currentshopAccountNickname").text(order.currentshopAccountNickname);
          	
          	console.log(order.product);
          	
          	$("#product").empty();
          	var productString = '';
          	for(var i=0;i<order.product.length;i++){
         		productString += '<tr>';
          		productString += 	'<td class="text-center" id="productId">'+order.product[i].productId+'</td>';
       			productString += 	'<td class="text-center">';
    			productString += 	'    <a href="${webPath}toProductEdit/'+order.product[i].productId+'" target="_blank"  id="productTitle">'+order.product[i].name+'</a>';
          		productString += 	'</td>';
          		productString += 	'<td class="text-center" ><img src="'+order.product[i].image+'" width="80px"></td>';
          		productString += 	'<td class="text-center" >尺寸：'+order.product[i].size+'<br>颜色：'+order.product[i].color+'<br>风格：'+order.product[i].style+'<br>加工方式：'+order.product[i].processingMethods+'</td>';
          		productString += 	'<td class="text-center" >'+order.product[i].salesPrice+'</td>';
          		productString += 	'<td class="text-center" >'+order.product[i].count+'</td>';
          		productString += 	'<td class="text-center" >'+order.product[i].productStatus+'</td>';
          		productString += 	'<td class="text-center" >'+order.product[i].totalPrice+'</td>';
          		productString += 	'<td class="text-center">';
    			if(""==order.product[i].certificateNumber){
    				productString += 	'<a class="btn btn-danger" onclick="savecertificateNumber('+order.product[i].productId+')" data-dismiss="modal" >添加</a>';
    			}else{
    				productString += 	'<a class="btn btn-danger" onclick="savecertificateNumber('+order.product[i].productId+')" data-dismiss="modal" >修改</a>';
    			}
          		productString += 	'</td>';
          		productString += '</tr>';
          	}
          	$("#product").append(productString);
          	
          	$("#productId").text(order.product.productId);
          	$("#productTitle").text(order.product.name);
          	$("#productImage").text(order.product.image);
          	$("#productPrice").text(order.product.salesPrice);
          	$("#productCount").text(order.product.count);
          	$("#productTotalPrice").text(order.product.totalPrice);
          	$("#certificateNumber").text(order.product.certificateNumber);
          	
          	$("#addressFullName").text(order.receiveAddress.fullName);
          	$("#addressMobileNumber").text(order.receiveAddress.mobileNumber);
          	$("#addressDetail").text(order.receiveAddress.address);
          	
          	$("#logisticsChannel").text(order.logistics.channel);
          	$("#logisticsNumber").text(order.logistics.number);
          }
      	})
   	});
</script>
<script type="text/javascript">

    $(document).ready(function () {
        var detail = function () {
            $('#detailModel').modal();
        };
        $('#detail').click(function () {
            detail();
        });
    });
    
    $(function () {
        $('.remark2').click(function () {
            var baseURL = "http://" + location.host + "/order/remark2";
            var order_id = $('#order_id').text();
            var remark2 = $('.remark2').parent().parent().find('input').val();
            var json_package = {
                "head": {"name": $.cookie("name"), "is_login": $.cookie("is_login")},
                "body": {"order_id": order_id, "remark2": remark2}
            };
            $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
                if (typeof result == 'string') result = JSON.parse(result);
                if (result.body.result == '0') {
                    alert('修改成功');
                    window.location.reload(true);
                } else {
                    alert(result.body.description)
                }
            })
        })
    })
    
    $(function () {
        $('.remark').click(function () {
            var baseURL = "http://" + location.host + "/order/remark";
            var order_id = $('#order_id').text();
            var remark = $('.remark').parent().parent().find('input').val();
            var json_package = {
                "head": {"name": $.cookie("name"), "is_login": $.cookie("is_login")},
                "body": {"order_id": order_id, "remark": remark}
            };
            $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
                if (typeof result == 'string') result = JSON.parse(result);
                if (result.body.result == '0') {
                    alert('修改成功');
                    window.location.reload(true);
                } else {
                    alert(result.body.description)
                }
            })
        })
    })
    
    $(function () {
        $('.refund').click(function () {
            var baseURL = "http://" + location.host + "/order/refund";
            var order_id = $(this).attr('data-id');
            var json_package = {
                "head": {"name": $.cookie("name"), "is_login": $.cookie("is_login")},
                "body": {"order_id": order_id}
            };
            $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
                if (typeof result == 'string') result = JSON.parse(result);
                if (result.body.result == '0') {
                    alert('退款成功');
                    window.location.reload(true);
                } else {
                    alert(result.body.description)
                }
            })
        })
    })
    
    $(function () {
        $('.refund-good').click(function () {
            var baseURL = "http://" + location.host + "/order/refund_good";
            var order_id = $(this).attr('data-id');
            var json_package = {
                "head": {"name": $.cookie("name"), "is_login": $.cookie("is_login")},
                "body": {"order_id": order_id}
            };
            $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
                if (typeof result == 'string') result = JSON.parse(result);
                if (result.body.result == '0') {
                    alert('确认成功');
                    window.location.reload(true);
                } else {
                    alert(result.body.description)
                }
            })
        })
    })
    
    function savecertificateNumber(index){
    	var orderId = "${orderId}";
    	$('#sendModel').modal();
        $("#orderId_hidden").val(orderId);
        $("#productId_hidden").val(index);
    }
        
    var deliver_certificate_number = function () {
        var baseURL = "${webPath}/order/updateCertificateNumber";
        var orderId = $("#orderId_hidden").val();
        var productId = $("#productId_hidden").val();
        var certificateNumber = $("#certificate_number").val();
        var json_package = {
            "head": {},
            "body": {"orderId": orderId, "productId": productId, "certificateNumber": certificateNumber}
        };
        $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
            if (typeof result == 'string') result = JSON.parse(result);
            if (result.body.result == '0') {
                alert('保存成功');
                window.location.reload(true);
            } else {
                alert(result.body.description)
            }
        })
    };
    
</script>
</body>
</html>
